package com.chengxusheji.service;

import javax.annotation.Resource;

 
import org.springframework.stereotype.Service;

import com.chengxusheji.mapper.AdminMapper; 
import com.chengxusheji.po.Admin;

@Service


public class AdminService {
	@Resource AdminMapper adminMapper;
	public String getErrMessage() { return this.errMessage; }
	
	private String errMessage;
	
	
	
	
	
	
	public boolean checkLogin(Admin admin) throws Exception { 
		Admin db_admin = (Admin) adminMapper.findAdminByUserName(admin.getUsername());
		if(db_admin == null) { 
			this.errMessage = " 账号不存在 ";
			System.out.print(this.errMessage);
			return false;
		} else if( !db_admin.getPassword().equals(admin.getPassword())) {
			this.errMessage = " 密码不正确! ";
			System.out.print(this.errMessage);
			return false;
		}
		
		return true;
	}
	public Admin findAdminByUserName(String name) throws Exception {
		Admin d= null;
		d= adminMapper.findAdminByUserName(name);
		return d;
	}

	
	public void changePassword(String name, String pwd) throws Exception {  
		Admin a = new   Admin();
		a.setUsername(name);
		a.setPassword(pwd);
		adminMapper.changePassword(a);  
	}
	
	
	
}
